<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class account extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();

        $this->load->library('auth');
    }

    public function index()
    {
        redirect('form/login');
    }

    public function login()
    {
        $username = $this->input->post('username');
        $password = $this->input->post('password');

        $error = $this->auth->login($username, $password);
        //$this->session->set_flashdata('error', $error);
        
        redirect('form/login');
    }

    public function register()
    {
        $this->load->model("crud/m_member");
        $this->load->model("crud/m_anggota");

        $id_anggota = $this->input->post("ID_ANGGOTA");
        $pass = $this->input->post("PASSWORD");
        $repass = $this->input->post("REPASSWORD");

        $isExist = $this->m_anggota->get_one($id_anggota);
        if($isExist)
        {
                $isExist = $this->m_member->get_one($id_anggota);
                if(!$isExist)
                {
                    $this->session->set_flashdata('success', "ID Anggota : $id_anggota<br/> telah terdaftar, silahkan login");
                    if($repass == $pass)
                        $this->response->data = $this->m_member->insert();
                    else
                        $this->session->set_flashdata('error', "Password dengan Ulangi Password tidak sama");
                }
                else
                    $this->session->set_flashdata('error', "ID Anggota ini telah terdaftar! <br/> Silahkan reset password anda dengan menghubungi Koperasi Palapa 85");
        }
        else
            $this->session->set_flashdata('error', "ID Anggota ini tidak valid");
        //$error = $this->auth->login($username, $password);
        //$this->session->set_flashdata('error', $error);

        redirect('form/login');
    }

    public function logout()
    {
        $this->session->sess_destroy();
        redirect('form/login');
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */